/**
 * @copyright   2010-2017, The Titon Project
 * @license     http://opensource.org/licenses/BSD-3-Clause
 * @link        http://titon.io
 */

// Default flex width.
$flex-width: 100% !default;

// Default flex gutter size.
$flex-gutter: false !default;

// Alias look-ups for flexbox alignments.
$flex-alignment-map: (
    top: flex-start,
    bottom: flex-end,
    left: flex-start,
    right: flex-end,
    center: center,
    between: space-between,
    around: space-around,
    stretch: stretch,
    baseline: baseline
);

/**
 * Calculate the width of an individual flex block. Take into account max widths and gutters.
 *
 * @param int $n - The current column
 * @param int $columns - The total number of columns
 * @param int [$width] - The max width of the flex container
 * @param int [$gutter] - The spacing in between each block
 */
@function flex-span($n, $columns, $width: $flex-width, $gutter: $flex-gutter) {
    @return span-width($n, $columns, $width, $gutter);
}

/**
 * Styles for the region that contains blocks.
 *
 * @param int [$width] - The max width of the flex container
 */
@mixin flex-region($width: $flex-width) {
    display: flex;
    max-width: $width;
}

/**
 * Align the blocks within a region horizontally or vertically.
 *
 * @param string [$align]
 */
@mixin flex-region-align($align: left) {
    justify-content: map-get($flex-alignment-map, $align);
}

/**
 * Set the orientation of blocks. Either display vertically or horizontally.
 *
 * @param string [$orientation]
 */
@mixin flex-region-orientation($orientation: horizontal) {
    @if ($orientation == vertical) {
        flex-direction: column;
    } @else {
        flex-direction: row;
    }
}

/**
 * Set the wrapping of blocks within a region.
 *
 * @param bool [$wrap]
 */
@mixin flex-region-wrap($wrap: true) {
    @if $wrap {
        flex-wrap: wrap;
        align-items: flex-start;
    } @else {
        flex-wrap: nowrap;
        align-items: stretch;
    }
}

/**
 * Set the width, grow, and shrink settings for a block.
 *
 * @param int|string [$width] - Default width basis
 * @param int [$grow]
 * @param int [$shrink]
 */
@mixin flex-block($width: auto, $grow: 1, $shrink: 0) {
    flex: $grow $shrink $width;
}

/**
 * Override the blocks alignment set by the parent.
 *
 * @param string [$align]
 */
@mixin flex-block-align($align: left) {
    align-self: map-get($flex-alignment-map, $align);
}

/**
 * Set the order of a block. Defaults to 100 so that custom blocks can be set higher.
 *
 * @param int [$order]
 */
@mixin flex-block-order($order: 100) {
    order: $order;
}

/**
 * Set a block to grow by default.
 *
 * @param int|string [$width]
 */
@mixin flex-block-grow($width: auto) {
    @include flex-block($width);
}

/**
 * Set a block to shrink by default.
 *
 * @param int|string [$width]
 */
@mixin flex-block-shrink($width: auto) {
    @include flex-block($width, 0, 1);
}
